package scales.utils.collection
import scala.collection.immutable.Stack
trait StackUtils {
@scala.annotation.tailrec
final def compareStack(p1: Stack[Int], p2: Stack[Int]): Int = {
if (p1.isEmpty && p2.isEmpty == false) {
1
} else if (p1.isEmpty == false && p2.isEmpty) {
-1
} else if (p1.isEmpty && p2.isEmpty) {
0
} else {
val t1 = p1.top
val t2 = p2.top
if (t1 == t2) {
compareStack(p1.pop, p2.pop)
} else {
if (t1 < t2)
1
else
-1
}
}
}
def sameBase(test: Stack[Int], against: Stack[Int]): Boolean = {
@scala.annotation.tailrec
def iSameBase(test: Stack[Int], against: Stack[Int]): Boolean = {
if (test.isEmpty && against.isEmpty == false) {
true
} else if (test.isEmpty == false && against.isEmpty) {
false
} else if (test.isEmpty && against.isEmpty) {
true
} else {
val t1 = test.top
val t2 = against.top
if (t1 == t2) {
iSameBase(test.pop, against.pop)
} else {
false
}
}
}
iSameBase(test, against)
}
}